package Day02.HomeWork;


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Scanner;

public class UserDemo {
    public static void main(String[] args) throws IOException {
        Scanner scn=new Scanner(System.in);
        String regex="[a-zA-Z0-9_]{1,32}$";
        System.out.println("请输入名字");
        String name= scn.next();
        boolean namet=name.matches(regex);
        if (!namet){
            System.out.println("用户名不正确");
            name=scn.next();
        }
        System.out.println("请输入密码");
        String pwd= scn.next();
        System.out.println("请输入缺口");
        String nick= scn.next();
        System.out.println("请输入年龄");
        int age=scn.nextInt();
        if(pwd.isEmpty()&&nick.isEmpty()) {
            System.out.println("输入结果为空");
            System.out.println("请重新输入");
            pwd = scn.next();
            nick = scn.next();
        }
        User user = new User(name,pwd,nick,age);
        System.out.println(user.toString());
        FileOutputStream fos = new FileOutputStream(user.getName()+".obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(user);
        oos.close();

    }



}
